# _*_ coding : utf-8 _*_
# @Time : 2023/8/24 20:00
# @Author : 寻梦
# @File : 06_get请求的urlencode方法
# @Project : code
import urllib.parse
import urllib.request
#'http://www.baidu.com/s?wd=周杰伦&sex=男'

data={
    "wd":"周杰伦",
    "sex":"男",
    "localtion":"中国台湾"
}

encodeDate= urllib.parse.urlencode(data)
print(encodeDate) #wd=%E5%91%A8%E6%9D%B0%E4%BC%A6&sex=%E7%94%B7&localtion=%E4%B8%AD%E5%9B%BD%E5%8F%B0%E6%B9%BE


base_url="https://www.baidu.com/s?"
url=base_url+encodeDate
print(url)
headers={
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 SLBrowser/8.0.1.5162 SLBChan/30"
}
requestobject=urllib.request.Request(url=url,headers=headers)
response=urllib.request.urlopen(requestobject)
content=response.read().decode('utf8')
print(content)